package com.yipinhouse.signing.app.appImpl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.api.R;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.signing.client.SigningManageClient;
import com.yipinhouse.signing.client.SigningQueryClient;
import com.yipinhouse.signing.client.param.DoSigningParam;
import com.yipinhouse.signing.client.result.HouseTradeResult;
import com.yipinhouse.signing.service.SigningService;
import com.yipinhouse.signing.service.dto.HouseTradeDto;
import com.yipinhouse.signing.service.param.DoSigningServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/signing")
public class SigningQueryApiImpl implements SigningQueryClient {

    @Resource
    private SigningService service;

    @Override
    public Result<List<HouseTradeResult>> getHouseTradeByUser(Integer userId) {
        log.info("根据用户id查询房屋交易记录：参数：{}",userId);
        List<HouseTradeDto> dto = service.getHouseTradeByUser(userId);
        List<HouseTradeResult> result = BeanUtil.copyToList(dto, HouseTradeResult.class);
        return Result.getInstanceList(HouseTradeResult.class).setMsg("根据用户id查询房屋交易记录成功！").setData(result);
    }

    @Override
    public Result getHouseTradeById(Integer houseTradeId) {
        log.info("根据id查询房屋交易记录：参数：{}",houseTradeId);
        HouseTradeDto dto = service.getHouseTradeById(houseTradeId);
        HouseTradeResult result = BeanUtil.toBean(dto, HouseTradeResult.class);
        return Result.getInstance(HouseTradeResult.class).setMsg("根据用户id查询房屋交易记录成功！").setData(result);
    }
}
